<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
        .slected {
            position: absolute;
            top: 45%;
            left: 45%;
            z-index: 9999;
            width: 25px;
        }

        .slecteddiv {
            position: absolute;
            height: 20px;
            bottom: 5px;
            left: 0px;
        }
    </style>
</head>

<body>
    <section id="div_goods_list" style="box-shadow:0 0 5px #ddd;overflow-x: scroll;" class="aui-margin-5 aui-flex-col aui-flex-left aui-flex-middle">

    </section>
    <section id="pic">
        <footer id="aui-footer" class="aui-flex-row aui-border-radius aui-margin-5 aui-flex-middle aui-flex-center" style="box-shadow:0 0 5px #ddd;margin-top:-2rem;">
            <div class="aui-flex-item-12 aui-text-center aui-flex-col aui-flex-center ">
                <div class="aui-padded-5 aui-text-center">
                    <img src="../image/loads.gif" class="aui-border-radius" id="sharepic" />
                </div>
            </div>
            <div class="aui-flex-item-12 aui-flex-row aui-flex-middle">
                <div class="aui-text-white aui-border-radius-bottom aui-text-center aui-font-size-16 aui-padded-5  aui-bg-tag-quan-0" id="tkmoney">
                </div>
            </div>
        </footer>
    </section>
    <div id="wenan" class="aui-flex-col aui-border-radius aui-margin-5 aui-flex-middle aui-flex-center aui-padded-5 aui-font-size-14" style="box-shadow:0 0 5px #ddd;z-index:9999">

    </div>
    <div id="shareicon" class="aui-flex-col aui-flex-middle aui-flex-center aui-padded-5">
        <div class="aui-col-5 aui-padded-5 aui-text-center" tapmode onclick="saveimg()">
            <img src="../image/save_01.png" />
            <p>保存图片</p>
        </div>
        <div class="aui-col-5 aui-padded-5 aui-text-center" tapmode onclick="sharewx('session')">
            <img src="../image/save_03.png" />
            <p>微信</p>
        </div>
        <div class="aui-col-5 aui-padded-5 aui-text-center" tapmode onclick="sharewx('tinimele')">
            <img src="../image/save_04.png" />
            <p>朋友圈</p>
        </div>
        <div class="aui-col-5 aui-padded-5 aui-text-center" tapmode onclick="shareqq('QFriend')">
            <img src="../image/save_06.png" />
            <p>QQ</p>
        </div>
        <div class="aui-col-5 aui-padded-5 aui-text-center" tapmode onclick="copyWenan()">
            <img src="../image/save_02.png" />
            <p>复制文案</p>
        </div>
    </div>
    <canvas id="sharecanvas" style="background-color:white; width:80%;display: none;" class="am-text-center am-center"></canvas>
    <script id="tmpl_goods_list" type="text/x-dot-template">
        <div class="aui-flex-item-4 aui-padded-5" tapmode onclick="select(0)">
            <img src="../image/order_on.png" class="slected aui-hide one_" data-img="{{=pageParam.itempic}}" id="one_" />
            <img src="{{=pageParam.itempic}}" height="120px" width="120px" class="" />
            <div class="slecteddiv aui-font-size-12 aui-flex-item-12 aui-text-white aui-text-center aui-bg-tag-quan aui-hide two_" id="two_">二维码图片</div>
        </div>
        {{~it:vo:index}}
        <div class="aui-flex-item-4 aui-padded-5" tapmode onclick="select({{=index}})">
            <img src="../image/order_on.png" class="slected aui-hide" id="select{{=index}}" data-img="{{=vo}}" />
            <img src="{{=vo}}" class="" height="120px" width="120px" />
            <div class="slecteddiv aui-font-size-12 aui-flex-item-12 aui-text-white aui-text-center aui-bg-tag-quan aui-hide">二维码图片</div>
        </div>
        {{~}}
    </script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/opensdk.js"></script>
<script type="text/javascript" src="../script/canvasImg.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript">
    var pageParam, erweima_url, imglist = new Array();
    imgs = new Array();
    apiready = function() {
        pageParam = api.pageParam.gooditem;
        if (typeof(pageParam.picurls) == 'string') {
            pageParam.picurls = pageParam.picurls.toString().split(',');
        }
        pageParam.itempic = pageParam.picurl;
        pageParam.taobao_image = pageParam.picurls;
        pageParam.itemprice = pageParam.price;
        pageParam.itemendprice = pageParam.price_after;
        pageParam.couponmoney = parseInt(pageParam.discount);
        pageParam.itemtitle = pageParam.goods_name;
        pageParam.itemid = pageParam.goods_id;
        pageParam.itemsale = pageParam.sales;
        pageParam.tkmoney = pageParam.commission;
        pageParam.itemdesc = pageParam.goods_name;
        imgs[0] = pageParam.itempic;
        imgs = imgs.concat(pageParam.taobao_image);
        setDotTmpl('tmpl_goods_list', 'div_goods_list', pageParam.taobao_image);
        $api.addCls($api.byId('one_'), 'aui-show');
        $api.addCls($api.byId('two_'), 'aui-show');
        if (pageParam.source_type == 'tb') {
            if ($api.getStorage('appSetInfo').sharetype == 1) {
                erweima_url = DOMAIN + '/share.html?pic=' + pageParam.itempic + '&kouling=' + pageParam.kouling;
            } else {
                erweima_url = '长按页面复制口令' + pageParam.kouling + '打开【手淘】领取优惠券';
            }
            pageParam.wenan = pageParam.itemtitle + '<br />\n' + '原价:' + pageParam.itemprice + '元<br />\n' + '优惠券:' + pageParam.couponmoney + '元<br />\n' + '券后价:' + pageParam.itemendprice + '元<br />\n' + '复制淘口令' + pageParam.kouling + '打开手淘领取优惠券' +
                '<br />\n推荐理由:' + pageParam.itemdesc;
        } else {
            erweima_url = pageParam.s_click_url;
            pageParam.wenan = pageParam.itemtitle + '<br />\n' + '原价:' + pageParam.itemprice + '元<br />\n' + '优惠券:' + pageParam.couponmoney + '元<br />\n' + '券后价:' + pageParam.itemendprice + '元<br />\n' + '优惠券链接:' + pageParam.s_click_url +
                '<br />\n推荐理由:' + pageParam.itemdesc;
        }
        makePic();
        $api.html($api.byId('tkmoney'), '预估分享奖励收益' + pageParam.tkmoney + '元');
        $api.html($api.byId('wenan'), pageParam.wenan);
        $('.aui-flex-item-4').click(function() {
            $(this).children('img').addClass('aui-show');
            $(this).siblings().children('img').removeClass('aui-show');
            $(this).children('div').addClass('aui-show');
            $(this).siblings().children('div').removeClass('aui-show');
            var newpic = $(this).children('img').attr('data-img');
            $api.attr($api.byId('sharepic'), 'src', '../image/loads.gif');
            makePic(newpic);
        })
    };

    function select(index) {

    }

    function copyWenan() {
        copyWord('Tip:' + pageParam.wenan.replace(/<br\s*\/>/gi, "\n"), true);
    }

    function saveimg() {
        showProgress();
        for (var i = 0; i < imgs.length; i++) {
            downloadFile(imgs[i], function(res) {
                if (res && i == imgs.length - 1) {
                    hideProgress();
                    showToast('保存成功!');
                } else {
                    //showToast('下载失败!');
                }
            })
        }

    }

    function sharewx(scene) {
        opensdk.wx.shareImage(scene, pageParam.picurl, pageParam.picurl);
    }

    function shareqq(type) {
        opensdk.qq.shareImage(type, pageParam.picurl);
    }

    function makePic(itempic) {
        pageParam.itempic = itempic || pageParam.itempic;
        CanvasImg.makeQrcode({text:erweima_url,itemid:pageParam.itemid}, function(ret) {
            CanvasImg.canvasGoodsImg('../image/bj.png', '../image/icon_' + pageParam.source_type + '.png', ret, pageParam, true, function(ret, img) {
                $api.attr($api.byId('sharepic'), 'src', ret);
                pageParam.picurl = img;
            });
        });
    }
</script>

</html>
